//
//  CCKSubscribeModel.m
//  budejieMe
//
//  Created by SuperJJ on 16/8/26.
//  Copyright © 2016年 SuperJJ. All rights reserved.
//

#import "CCKSubscribeModel.h"
#import "HMNetWorkManager.h"


@implementation CCKSubscribeModel

+(instancetype)subscribeModelWithDict:(NSDictionary *)dict
{
    CCKSubscribeModel *model = [CCKSubscribeModel new];
    
    [model setValuesForKeysWithDictionary:dict];
    
    return model;
}

-(void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    
}

+(void)downloadDataModelWithUrl:(NSString *)urlStr andSuccessBlock:(void(^)(NSArray *))successBlock andFailedBlock:(void(^)(NSError *))failedBlock
{
    
    [[HMNetWorkManager sharedNetWorkManager] GET:urlStr parameters:nil progress:nil success:^(NSURLSessionDataTask * _Nonnull task, NSDictionary *responseObject)
    {
        NSArray *array = responseObject[@"rec_tags"];
        
        NSMutableArray *mtArray = [NSMutableArray arrayWithCapacity:array.count];
        
        [array enumerateObjectsUsingBlock:^(NSDictionary * obj, NSUInteger idx, BOOL * _Nonnull stop)
        {
            [mtArray addObject:[self subscribeModelWithDict:obj]];
        }];
        
        if (successBlock)
        {
            successBlock(mtArray.copy);
        }
        
    } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error)
    {
        if (failedBlock)
        {
            failedBlock(error);
        }
    }];
}



@end
